Skip to content

fix(chunker): platform-independent hash_item + collapse single-child root - #244

Merged
zhangfengcdt merged 3 commits into
mainfrom
codex/resolve-pr-193
Aug 25, 2026
Merged

fix(chunker): platform-independent hash_item + collapse single-child root#244
zhangfengcdt merged 3 commits into
mainfrom
codex/resolve-pr-193

Conversation

@zhangfengcdt

Copy link
Copy Markdown
Owner

Resolved version of #193 against current main. Preserves prefix-free hashing and structural-diff coverage already merged, plus the chunker canonicality changes and invariant tests from #193. Supersedes #193 after CI passes.

presempathy-awb and others added 3 commits July 2, 2026 12:01
The tree is content-addressed, so equal get_hash() => byte-identical
subtree. The old diff descended incorrectly and could silently drop
changes (root-only style data loss). Rewrite diff_nodes_recursive to:
short-circuit equal-hash subtrees, merge-join leaf pairs, and for
internal nodes skip children whose stored child-hash matches (O(diff),
no load) — flattening only the divergent region. Kept honest by a
#[cfg(test)] full-leaf flatten oracle (diff_nodes_flatten) that every
new differential test asserts byte-identical against, plus ground-truth
add/remove/modify assertions. Old diff_recursive retained (dead_code).

Uses only existing APIs; no format/hash change. Tests: mod odiff_differential.
…single-child root

Two content-defined-chunker canonicality bugs:

1. hash_item fed the item through the slice Hash impl, which prefixes a
   platform-width usize length (8 bytes native, 4 on wasm32) before the
   bytes — so chunk boundaries, and thus every tree's shape and root
   hash, DIFFER between 32- and 64-bit targets. Use hasher.write(item)
   to hash the raw content bytes only (in streaming_chunker and in
   ProllyNode's NodeChunk). Deterministic across targets.

2. A content-defined boundary on the final item could leave the root a
   single-child internal node — a non-minimal spine diverging from a
   fresh batch build. Collapse single-child internal roots in done().

Because merge() diffs internally, the new boundaries surface the
root-only diff data-loss bug during merge, so this fix REQUIRES the
canonical-structural-diff fix (this branch is stacked on it). Golden
value in test_delete updated for the corrected boundary.

Tests: mod chunker_invariants.
@zhangfengcdt
zhangfengcdt merged commit 7b69caf into main Aug 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants